<template>
  <div class="app-container">
    <el-form :inline="true" :model="searchMap.data" class="demo-form-inline">
      <el-form-item>
        <el-input
          v-model="searchMap.data.userName"
          placeholder="用户名"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="searchTable()">查询</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="userInfoList" style="width: 100%">
      <el-table-column prop="userName" label="用户名" width="180">
      </el-table-column>

      <el-table-column prop="account" label="登录账户"> </el-table-column>

      <el-table-column prop="userType" label="人员类型">
        <template slot-scope="scope">
          <p v-if="scope.row.userType == 1">客服账号</p>
          <p v-if="scope.row.userType == 2">管理账号</p>
          <p v-if="scope.row.userType == 3">内置账号</p>
          <p v-if="scope.row.userType == 4">财务账号</p>
          <p v-if="scope.row.userType == 5">物流账号</p>
          <p v-if="scope.row.userType == 6">其他账号</p>
        </template>
      </el-table-column>

      <el-table-column prop="loginTime" label="最后登陆时间"></el-table-column>

      <el-table-column prop="" label="操作">
        <template slot-scope="scope">
          <el-button
            type="primary"
            icon="el-icon-edit"
            @click="handledit(scope.row)"
            >修改</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
    style="float: right"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="searchMap.page"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="5"
      layout="total, sizes, prev, pager, next, jumper"
      :total="this.total"
    >
    </el-pagination>
    <!-- 修改用户 -->
    <el-dialog
      title="用户修改"
      :visible.sync="dialogFormVisible"
      :close-on-click-modal="false"
    >
      <el-form :model="userInfo">
        <el-form-item label="用户名" :label-width="formLabelWidth">
          <el-input v-model="userInfo.userName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="备注" :label-width="formLabelWidth">
          <el-input v-model="userInfo.remark" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="editeDate()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { search, edit } from "@/api/userInfo";
export default {
  data() {
    return {
      total: 0,
      searchMap: {
        page: 1,
        limit: 5,
        data: {},
      },
      userInfoList: [],
      userInfo: {}, //用户信息
      dialogFormVisible:false,
    };
  },
  methods: {
    //搜索
    searchTable() {
      var _this = this;
      // if(this.searchMap.data.name=""){
      //   this.searchMap.data={};
      // }
      var searchMap1= {
        page: 1,
        limit: 5,
        data: {},
      };
      if (this.searchMap.data.userName==""){
        search(searchMap1).then((res) => {
        _this.userInfoList = res.data;
        _this.total = res.total;
      });
      }else{
         search(this.searchMap).then((res) => {
        _this.userInfoList = res.data;
        _this.total = res.total;
      });
      }
    },
    //修改
    handledit(row){
      this.userInfo=row
      this.userInfo.userId=row.userId
      this.dialogFormVisible=true
    },
    editeDate(){
      edit(this.userInfo).then(res=>{
        if (res.success) {
          this.searchTable();
          this.$message({
            showClose: true,
            message: res.msg,
            type: "success",
          });
        } else {
          this.$message({
            showClose: true,
            message: res.msg,
            type: "error",
          });
        }
        this.dialogFormVisible=false
      })
    },
    handleSizeChange(size) {
      this.searchMap.limit = size;
      this.search();
    },
    handleCurrentChange(currentPage) {
      this.searchMap.page = currentPage;
      this.search();
    },
  },
  created() {
    let that = this;
    that.searchTable();
  },
};
</script>